# RUN: tf-mlir-translate -graphdef-to-mlir -tf-enable-shape-inference-on-import=false %s -o - | FileCheck %s

# Verify that a NextIteration node feeding two different merge nodes is properly
# Imported.

# CHECK-LABEL: func @main()
# CHECK:         %[[NEXTITERATION:[a-z_0-9]+]], {{.*}} = tf_executor.NextIteration.Source
# CHECK:         tf_executor.Merge {{.*}}, %[[NEXTITERATION]]
# CHECK:         tf_executor.Merge {{.*}}, %[[NEXTITERATION]]

node {
  name: "Const"
  op: "Const"
  attr {
    key: "dtype"
    value {
      type: DT_INT32
    }
  }
  attr {
    key: "value"
    value {
      tensor {
        dtype: DT_INT32
        tensor_shape {
        }
        int_val: 0
      }
    }
  }
}
node {
  name: "Enter"
  op: "Enter"
  input: "Const"
  attr {
    key: "T"
    value {
      type: DT_INT32
    }
  }
  attr {
    key: "frame_name"
    value {
      s: "while_context"
    }
  }
  attr {
    key: "is_constant"
    value {
      b: false
    }
  }
  attr {
    key: "parallel_iterations"
    value {
      i: 10
    }
  }
}
node {
  name: "Merge"
  op: "Merge"
  input: "Enter"
  input: "NextIteration"
  attr {
    key: "N"
    value {
      i: 2
    }
  }
  attr {
    key: "T"
    value {
      type: DT_INT32
    }
  }
}
# The following node also takes NextIteration node as input.
node {
  name: "Use_NextIteration_Again"
  op: "Merge"
  input: "Enter"
  input: "NextIteration"
  attr {
    key: "N"
    value {
      i: 2
    }
  }
  attr {
    key: "T"
    value {
      type: DT_INT32
    }
  }
}
node {
  name: "Add/y"
  op: "Const"
  attr {
    key: "dtype"
    value {
      type: DT_INT32
    }
  }
  attr {
    key: "value"
    value {
      tensor {
        dtype: DT_INT32
        tensor_shape {
        }
        int_val: 1
      }
    }
  }
}
node {
  name: "Add"
  op: "Add"
  input: "Merge"
  input: "Add/y"
  attr {
    key: "T"
    value {
      type: DT_INT32
    }
  }
}
node {
  name: "NextIteration"
  op: "NextIteration"
  input: "Add"
  attr {
    key: "T"
    value {
      type: DT_INT32
    }
  }
}
library {
}
versions {
  producer: 62
}

